package org.kernely.security.ui.user.mgmt;

import org.kernely.ui.mvp.IKernelyView;

import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;

/**
 * UserManagementView class
 */
public class UserManagementView extends GridLayout implements IKernelyView{
	/**
	 * The View ID
	 */
	public final static Class<? extends IKernelyView> ID_VIEW = UserManagementView.class;
	
	/**
	 * The Serial Version ID
	 */
	private static final long serialVersionUID = 15612318602354L;

	private HorizontalLayout hlayout;
	private Button bAddUser;
	private Button bEditUser;
	private Button stateButton;
	private Table table;
	private final CheckBox showDisabledUser;
	
	/**
	 * @see org.kernely.core.service.IKernelyView#getComponent()
	 */
	public Component getComponent() {
		return this;
	}

	/**
	 * UserManagementView's constructor
	 */
	public UserManagementView(){
		// Configuration of the GridLayout
		this.setRows(2);
		this.setColumns(1);
		
		this.hlayout = new HorizontalLayout();
		this.bAddUser = new Button("Add an user");
		this.bEditUser = new Button("Edit an user");
		this.bEditUser.setEnabled(false);
		this.stateButton = new Button("Enable/Disable");
		this.stateButton.setEnabled(false);
		this.showDisabledUser = new CheckBox("Display disabled users");
		this.showDisabledUser.setValue(true);
		
		bEditUser.setImmediate(true);
		stateButton.setImmediate(true);
		this.table = new Table();
		
		this.table.setSizeFull();
		this.table.setPageLength(0);
		this.table.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		
		this.table.addContainerProperty("Name", String.class, null);
		this.table.addContainerProperty("Firstname", String.class,  null);
		this.table.addContainerProperty("Mail", String.class,  null);
		this.table.addContainerProperty("Groups", String.class, null);
		this.table.addContainerProperty("Enabled", String.class,  null);
		this.table.setSelectable(true);
		this.table.setImmediate(true);
		this.table.setPageLength(20);
		
		this.table.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY);
		this.table.setSortContainerPropertyId("Name");
		this.table.setSortAscending(true);
		
		this.hlayout.addComponent(this.bAddUser);
		this.hlayout.addComponent(this.bEditUser);
		this.hlayout.addComponent(this.stateButton);
		this.hlayout.addComponent(this.showDisabledUser);
		this.hlayout.setMargin(true, true, true, true);
		this.hlayout.setSpacing(true);
		
		this.addComponent(this.hlayout,0, 0);
		this.addComponent(this.table, 0, 1);
		
		this.setSizeFull();
	}

	/**
	 * Return the "add an user" button
	 * @return the specific button
	 */
	public final Button getbAddUser() {
		return bAddUser;
	}

	/**
	 * Return the "edit an user" button
	 * @return the specific button
	 */
	public final Button getbEditUser() {
		return bEditUser;
	}

	/**
	 * Return the state button (enable/disable)
	 * @return the state button
	 */
	public final Button getStateButton() {
		return stateButton;
	}
		
	/**
	 * Return the table containing users
	 * @return the table
	 */
	public final Table getTable() {
		return table;
	}

	/**
	 * @return the showDisabledUser
	 */
	public final CheckBox getShowDisabledUser() {
		return showDisabledUser;
	}
	
	
}
